<template>
  <div class="displayCor">

    <el-table
      :data="tableData"
      height="100%"
      border
      style="width: 90%">
      <el-table-column
        prop="id"
        label="课程id"
        width="100">
      </el-table-column>
      <el-table-column
        prop="name"
        label="课程姓名"
        width="100">
      </el-table-column>
      <el-table-column
        prop="level"
        label="年级"
        width="100">
      </el-table-column>
      <el-table-column
        prop="week"
        label="上课时间"
        width="100">
      </el-table-column>
      <el-table-column
        prop="time"
        width="100">
      </el-table-column>
      <el-table-column
        prop="time_class"
        label="课程时长"
        width="100">
      </el-table-column>
      <el-table-column
        prop="loc"
        label="上课地点"
        width="100">
      </el-table-column>
      <el-table-column
        prop="tname"
        label="任课教师"
        width="100">
      </el-table-column>
      <el-table-column
        prop="info"
        label="课程信息"
        width="200">
      </el-table-column>
      <el-table-column
        prop="max_num"
        label="最大容纳人数"
        width="80">
      </el-table-column>
      <el-table-column
        prop="now_num"
        label="目前课程人数"
        width="80">
      </el-table-column>
      <el-table-column fixed="right" label="操作" width="200">
        <template slot-scope="scope">
          <el-button type="primary" icon="el-icon-edit" circle @click="update(scope.$index,scope.row)" ></el-button>
          <el-button type="danger" icon="el-icon-delete" circle @click="handleDelete(scope.$index, scope.row)">
          </el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
export default {
  methods: {
    update(index,row){

    },

    handleDelete(index,row){
      let _this=this;
      this.$axios({
        method:'GET',
        url:'http://localhost/course/deleteById/'+row.id
      }).then(result => {
        this.$message({
          message: '已删除！',
          type: 'success'
        })
      })
      _this.$axios({
        method:'GET',
        url:'http://localhost/course/findAll',

      }).then(response=>{

        _this.tableData=response.data
      })
    },
    action() {
      let _this = this
      let responseData=[]
      this.$axios({
        method: 'GET',
        url: 'http://localhost/course/findAll',

      }).then(response => {

        let user = response.data
        for (let i of user) {
          responseData.push(i)

        }

        _this.tableData=responseData

      })
    },

  },
  mounted() {
   this.action()
  },
  data() {
    return {
      tableData: [],
    }
  },

}
</script>

<style scoped>
.displayCor{
  position: absolute;
  width: 100%;
  height: 600px;
}

</style>
